{
  LW Handler -- LightWave Instance Handlers

  This unit contains the definition of a basic handler.  A handler
  is a special kind of server that manages a persistent instance.

  Based on lwhandler.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit LW_Handler;

{$mode delphi}{$H+}

interface

uses
  LW_IO    ,
  LW_Types ,
  LW_XPanel;

const
  LWINTERFACE_VERSION = 4;
  LWINSTUPDATE_GLOBAL = 'Instance Update';

type
  {
    Handlers of all types have a class name of the form "*Handler", and
    take a handler struct as the local data to the Activate function.
    The Activate function fills in the handler fields and returns.
  }
  PLWInstanceFuncs = ^TLWInstanceFuncs;
  TLWInstanceFuncs = record
    Priv: Pointer;

    Create:  function
             (      Priv      : Pointer     ;
                    Context   : Pointer     ;
                    Error     : PPLWError   ) : PLWInstance;
    Destroy: procedure
             (      Instance  : PLWInstance ) ;
    Copy:    function
             (      Instance  : PLWInstance ;
                    From      : PLWInstance ) : PLWError   ;
    Load:    function
             (      Instance  : PLWInstance ;
              const LoadState : PLWLoadState) : PLWError   ;
    Save:    function
             (      Instance  : PLWInstance ;
              const SaveState : PLWSaveState) : PLWError   ;
    DescLn:  function
             (      Instance  : PLWInstance ) : PChar      ;
  end;

  PLWHandler = ^TLWHandler;
  TLWHandler = record
    Inst: PLWInstanceFuncs;
  end;

  {
    User interfaces for handlers are defined as separate servers with
    class names of the form "*Interface".  Their Activate functions take
    an LWInterface structure which they should fill in.  The 'panel'
    field can be set to point to the non-modal controls for one or more
    instances.  Otherwise the 'options' function should be set to open a
    modal dialog for a single instance.  The 'command' function can be
    set to provide batch commands to operate on instances.

    Technically this is version 2 of the plugin interface, but for
    compatibility with legacy UI code, which checks against the handler
    class API version, all versions less than LWINTERFACE_VERSION will be considered version
    1 API functions.  New plugins MUST return AFUNC_BADVERSION when called
    with a version less than LWINTERFACE_VERSION.
  }
  PLWInterface = ^TLWInterface;
  TLWInterface = record
    Inst:  PLWInstance;
    Panel: PLWXPanel;

    Options: function
             (      Instance : PLWInstance) : PLWError;
    Command: function
             (      Instance : PLWInstance;
              const Command  : PChar      ) : PLWError;
  end;

  {
    Because the UI for instances can now operate in a non-modal fashion,
    handlers need to inform the host when their instance data have changed
    in a way that will affect the host.  They can do this by getting the
    "Instance Update" global function.  This can be called at any point
    with the class name of the instance and the instance pointer itself,
    and the host will respond to any changes.
  }
  TLWInstUpdate = procedure
                  (const ClassName : PChar      ;
                         Instance  : PLWInstance) ;

implementation

end.

